{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "de7d73c0",
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "65fcc022",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = torch.rand(1,2,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "74ac16f9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[0.8890, 0.4414, 0.5684],\n",
       "         [0.2574, 0.8244, 0.2390]]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "39600b74",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Size([1, 2, 3])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f181610b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[0.8890, 0.4414, 0.5684],\n",
       "        [0.2574, 0.8244, 0.2390]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "75b6f8f9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(a.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "630f2b39",
   "metadata": {},
   "source": [
    "# Dim = 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "1f2801fa",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = torch.rand(2,3,28,28) # （2张图片，3个通道，28*28像素）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "00d33900",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[[0.6490, 0.3479, 0.7928,  ..., 0.2038, 0.7448, 0.7571],\n",
       "          [0.4962, 0.4547, 0.5481,  ..., 0.4321, 0.7306, 0.6364],\n",
       "          [0.7162, 0.8416, 0.6739,  ..., 0.5655, 0.7159, 0.8141],\n",
       "          ...,\n",
       "          [0.7144, 0.7969, 0.6310,  ..., 0.5410, 0.4326, 0.6524],\n",
       "          [0.2668, 0.5054, 0.1115,  ..., 0.5311, 0.2743, 0.1620],\n",
       "          [0.4656, 0.4113, 0.3113,  ..., 0.2569, 0.2168, 0.2920]],\n",
       "\n",
       "         [[0.4639, 0.8627, 0.2009,  ..., 0.7908, 0.1464, 0.4734],\n",
       "          [0.2270, 0.5545, 0.6688,  ..., 0.8334, 0.6222, 0.0626],\n",
       "          [0.0565, 0.0434, 0.8027,  ..., 0.6540, 0.0242, 0.6511],\n",
       "          ...,\n",
       "          [0.3793, 0.2650, 0.5004,  ..., 0.2786, 0.0061, 0.9679],\n",
       "          [0.9192, 0.5676, 0.8694,  ..., 0.2277, 0.1755, 0.5065],\n",
       "          [0.2163, 0.2080, 0.5568,  ..., 0.9653, 0.1032, 0.3464]],\n",
       "\n",
       "         [[0.0096, 0.4946, 0.8446,  ..., 0.1567, 0.8062, 0.3761],\n",
       "          [0.2470, 0.1926, 0.2411,  ..., 0.2125, 0.1252, 0.8604],\n",
       "          [0.8059, 0.4946, 0.2913,  ..., 0.5732, 0.2155, 0.5053],\n",
       "          ...,\n",
       "          [0.8362, 0.1733, 0.1383,  ..., 0.8005, 0.0416, 0.2515],\n",
       "          [0.0873, 0.6088, 0.9594,  ..., 0.3864, 0.0264, 0.0586],\n",
       "          [0.7936, 0.4140, 0.2328,  ..., 0.6740, 0.8793, 0.2339]]],\n",
       "\n",
       "\n",
       "        [[[0.7549, 0.6617, 0.4843,  ..., 0.6732, 0.5473, 0.3559],\n",
       "          [0.1245, 0.2223, 0.0439,  ..., 0.1952, 0.9204, 0.8730],\n",
       "          [0.2928, 0.6055, 0.3133,  ..., 0.6877, 0.4341, 0.7973],\n",
       "          ...,\n",
       "          [0.4346, 0.3552, 0.1933,  ..., 0.0589, 0.9245, 0.5059],\n",
       "          [0.1438, 0.1456, 0.1171,  ..., 0.7604, 0.5294, 0.8716],\n",
       "          [0.2528, 0.5129, 0.1168,  ..., 0.3040, 0.7614, 0.7949]],\n",
       "\n",
       "         [[0.8622, 0.2787, 0.8233,  ..., 0.1509, 0.2407, 0.4542],\n",
       "          [0.1881, 0.3837, 0.6966,  ..., 0.4194, 0.8973, 0.9924],\n",
       "          [0.5536, 0.3962, 0.0803,  ..., 0.2402, 0.3520, 0.8400],\n",
       "          ...,\n",
       "          [0.2211, 0.8321, 0.0355,  ..., 0.1420, 0.5695, 0.5795],\n",
       "          [0.5565, 0.1158, 0.8013,  ..., 0.7149, 0.2559, 0.3818],\n",
       "          [0.5586, 0.3265, 0.1478,  ..., 0.4857, 0.4318, 0.2356]],\n",
       "\n",
       "         [[0.9489, 0.3832, 0.5092,  ..., 0.8988, 0.6713, 0.3057],\n",
       "          [0.3934, 0.2266, 0.6626,  ..., 0.6310, 0.3061, 0.4343],\n",
       "          [0.5931, 0.6146, 0.0836,  ..., 0.8457, 0.7783, 0.0635],\n",
       "          ...,\n",
       "          [0.1848, 0.0252, 0.7644,  ..., 0.0805, 0.4479, 0.4128],\n",
       "          [0.8008, 0.2691, 0.2750,  ..., 0.1960, 0.5486, 0.2996],\n",
       "          [0.3832, 0.5172, 0.5763,  ..., 0.1227, 0.6094, 0.3444]]]])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "db0e5e01",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Size([2, 3, 28, 28])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "8cfcd116",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4704"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.numel() # numel是指tensor占用的内存大小"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "f987a512",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.dim()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "468a3b32",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = torch.tensor(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "c352c271",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.dim()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0b51c560",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
